package com.xmut.mall.store.controller;

import com.xmut.mall.store.entity.StoreRegionEntity;
import com.xmut.mall.store.service.StoreRegionService;
import com.xmut.mall.store.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("store/storeregion")
public class StoreRegionController {

    @Autowired
    private StoreRegionService storeRegionService;

    /**
     * 初始化地区选择器
     *
     * @return
     */
    @GetMapping("/initRegion")
    public RespBean initRegion() {
        List<StoreRegionEntity> list = storeRegionService.initRegion();
        return RespBean.success("获取成功", list);
    }

    /**
     * 根据父Id获取地区信息
     * @param parentId
     * @return
     */
    @GetMapping("/getRegionByParentId/{parentId}")
    public RespBean getRegionByParentId(@PathVariable Long parentId){
        List<StoreRegionEntity> list = storeRegionService.getRegionByParentId(parentId);
        return RespBean.success("获取地区信息成功",list);
    }
}
